package org.kyw.auth.service.impl;

import org.kyw.auth.domain.Permission;
import org.kyw.auth.mapper.PermissionMapper;
import org.kyw.auth.mapper.RoleMapper;
import org.kyw.auth.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class PermissionServiceImpl implements IPermissionService {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public Map<String, Object> queryPermissionByRoleId(Long roleId) {
        Map<String, Object> map = new HashMap<>();
        List<Permission> permissions = permissionMapper.loadOneAndTwoTree();
        List<Long> myPermissionids = roleMapper.getMyPermissionidsByRoleId(roleId);
        map.put("permissions", permissions);
        map.put("myPermissionids", myPermissionids);
        map.put("rid", roleId);
        return map;
    }

    @Override
    public List<String> loadPermissionUrlsByEmpId(Long id) {
        return permissionMapper.loadPermissionUrlsByEmpId(id);
    }

    @Override
    public List<String> loadAllUrls() {
        return permissionMapper.loadAllUrls();
    }
}
